import * as XLSX from "xlsx";
import FileSaver from "file-saver";

// 按照惯例，组合式函数名以“use”开头
export function make_excel_file(table_name: string, table_id: string) {
    // 被组合式函数封装和管理的状态

    let a = table_name
    let b = table_id

    const exportClick1 = () => {
        const wb = XLSX.utils.table_to_book(document.querySelector('#' + b));//关联dom节点
        /* get binary string as output */
        const wbout = XLSX.write(wb, {
            bookType: 'xlsx',
            bookSST: true,
            type: 'array'
        })
        try {
            FileSaver.saveAs(new Blob([wbout], {
                type: 'application/octet-stream'
            }), a + '.xlsx')  //自定义文件名
        } catch (e) {
            if (typeof console !== 'undefined') console.log(e, wbout);
        }
        return wbout
    }
    return exportClick1()
}